package com.opentd.graphics.screen;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;

import javax.swing.ImageIcon;

import com.opentd.game.Game;
import com.opentd.graphics.Button;
import com.opentd.graphics.Level;

public class EndScreen extends Screen{

	public static Image bg = new ImageIcon("dat/img/end_screen_bg.png").getImage();
	public static Button restartButton;
	public static Button backButton;
	
	private static boolean isFirst = true;
	
	public static void draw(Graphics g) {
		if(isFirst){
			restartButton = new Button((Game.panel.getWidth() / 2) - 100, 200, Game.Button.RESTART_BUTTON);
			backButton = new Button((Game.panel.getWidth() / 2) - 100, 310, Game.Button.BACK_BUTTON);
			isFirst = false;
		}
		g.drawImage(bg, 0,  0, Game.panel.getWidth(), Game.panel.getHeight(),null);
		g.setColor(new Color(150, 150, 150));
		g.setFont(new Font(Font.DIALOG, Font.BOLD, 32));
		g.drawString(Game.selectedLevel.won ? "You won!" : "You lost!", 100, 100);
		
		restartButton.draw(g);
		backButton.draw(g);
	}
	
	public static void handleClick(Point p){
		if(restartButton.contains(p)){
	    	Game.selectedLevel.reset();
			Game.State.currentScreen = Game.State.GAME_SCREEN;
		} else if(backButton.contains(p)){
			Game.State.currentScreen = Game.State.MAIN_SCREEN;
	    	Game.selectedLevel.reset();
		}
	}

}
